package com._函数接口;

import java.util.Arrays;
import java.util.Random;
import java.util.stream.Stream;

public class StreamOperate {
    public static void main(String[] args) {
        String[] arr = {"a", "h", "i", "j", "k", "l", "m", "n", "o", "b", "c", "d", "e", "f", "g", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        // 1.数组
        Arrays.stream(arr).forEach(System.out::println);
        System.out.println("--------------------------------");
        Arrays.stream(arr).sorted().forEach(System.out::println);
        System.out.println("--------------------------------");
        //2.list
        Arrays.asList(arr).stream().sorted().forEach(System.out::println);
        //3.stream
        Stream.of(arr).forEach(System.out::println);
        System.out.println("--------------------------------");
        Stream.iterate(1,i->i+1).limit(10).forEach(System.out::println);
        System.out.println("--------------------------------");
        Stream.generate(Math::random).limit(10).forEach(System.out::println);
        System.out.println("--------------------------------");
        Stream.generate(()->new Random().nextInt(10)).limit(10).forEach(System.out::println);
        System.out.println("--------------------------------");
        //输出依次 b e l o
        String[] arrays={"","java","jdk8","demo","bo_le","","jdk8"};
        Arrays.stream(arrays)
                .distinct()
                .filter(i->!i.isEmpty())
                .sorted()
                .limit(1)
                .map(i->i.replace("_",""))
                .flatMap(i->Stream.of(i.split("")))
                .sorted()
                .forEach(System.out::println);

    }
}
